package com.st.emps.achievements.service;

import java.util.ArrayList;
import java.util.List;

import com.st.emps.achievements.dao.AchievementsDao;
import com.st.emps.achievements.model.AchievementsModel;
import com.st.emps.project.model.ProjectModel;


public class AchievementsService {
	private AchievementsDao dao = new AchievementsDao();
	
	public String insert(AchievementsModel model) {
		
		return selectModel(model)==null? dao.insert(model)+"":"repeat";

	}
	public String delete(AchievementsModel model) {
			return dao.delete(model)+"";
	}
	public String update(AchievementsModel model) {
		return dao.update(model)+"";

	}
	public List<AchievementsModel> selectList(AchievementsModel model) {
		String code = model.getCode();
		if(code==null)
			code ="";
		model.setCode("%"+code+"%");
		return dao.select(model);

	}
	public AchievementsModel selectModel(AchievementsModel model) {
		AchievementsModel tmp = new AchievementsModel();
		List<AchievementsModel> list = new ArrayList<AchievementsModel>();
		tmp.setCode(model.getCode());
		list = dao.select(tmp);
		if(list!=null&&!list.isEmpty())
		return list.get(0);
		return null;

	}
	public Object selectCount(AchievementsModel model) {
		AchievementsModel tmp = new AchievementsModel();
		String code = model.getCode();
		if(code==null)
			code ="";
		tmp.setCode("%"+code+"%");
		return dao.selectCount(tmp);
	}
	
	public String updateProject(AchievementsModel model) {
		dao.updateProject(model);
		AchievementsModel tmp = selectModel(model);
		return dao.updateDepart(tmp)+"";
	}
}

